<template>
  <div class="white-box">
    <div class="table-mb">
      <el-button type="primary" @click="handleAdd()" :icon="CirclePlus">添加</el-button>
    </div>
    <div class="task-one">
      <div class="task-one__item">
        <span class="task-one__label">等级名称：</span>
        <el-input placeholder="请输入" v-model="searchParams.gradeName" @keyup.enter.native="handleSearch" clearable></el-input>
      </div>
      <div class="task-one__item">
        <span class="task-one__label">会员数量：</span>
        <el-input placeholder="请输入" v-model="searchParams.memberNum" @keyup.enter.native="handleSearch" clearable></el-input>
      </div>
      <div class="task-one__item">
        <span class="task-one__label">消费金额：</span>
        <el-input placeholder="请输入" v-model="searchParams.amount" @keyup.enter.native="handleSearch" clearable></el-input>
      </div>
      <div class="task-one__btn">
        <el-button type="primary" :loading="searchBtnLoading" :icon="Search"
                   @click="handleSearch">搜索</el-button>
      </div>
    </div>

    <el-table class="table-mb" v-loading="loading" :data="list" :header-cell-style="{ background: '#F5F7FA' }"
              element-loading-background="rgba(255, 255, 255, 0.6)" row-key="sid">
      <el-table-column prop="gradeName" label="等级名称"></el-table-column>
      <el-table-column prop="memberNum" label="会员数量"></el-table-column>
      <el-table-column prop="amount" label="消费金额"></el-table-column>
      <el-table-column align="center" prop="status" label="状态"  width="100">
        <template #default="{ row }">
          <el-text v-if="row.status === 0" type="success">正常</el-text>
          <el-text v-else-if="row.status === 1" type="info">停用</el-text>
          <el-text v-else type="info"></el-text>
        </template>
      </el-table-column>
      <el-table-column prop="created" label="创建时间" width="160"> </el-table-column>
      <el-table-column label="操作" width="180" fixed="right">
        <template #default="{ row }">
          <el-button link type="primary" @click="handleEdit(row,{sid:row.sid})">编辑</el-button>
<!--          <el-popconfirm :persistent="false" title="确定删除吗？" confirm-button-text="确定" cancel-button-text="取消"-->
<!--                         @confirm="handleDelete(row.sid)">-->
<!--            <template #reference>-->
<!--              <el-button link type="danger">删除</el-button>-->
<!--            </template>-->
<!--          </el-popconfirm>-->
          <el-popconfirm :persistent="false" title="确定删除吗？" confirm-button-text="确定" cancel-button-text="取消"
                         @confirm="handleAction('delete',`/member/grade/batchDel`,{sidList:[row.sid]})">
            <template #reference>
              <el-button link type="danger">删除</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        background
        v-model:current-page="page"
        v-model:page-size="pageSize"
        :page-sizes="pageSizeNum"
        :total="totalNums"
        layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>

    <el-dialog v-model="dialogShow" :title="dialogParams.type == 'add'?'添加':'编辑'" width="660px" :append-to-body="true" :destroy-on-close="true" :close-on-click-modal="false" @close="closeDialog">
      <el-form ref="dialogFormRef" :model="dialogForm" :rules="dialogFormRules" label-width="120px" style="width: 560px">
        <el-form-item label="等级名称" prop="gradeName">
          <el-input v-model.trim="dialogForm.gradeName" clearable placeholder="请输入等级名称"/>
        </el-form-item>
<!--        <el-form-item label="会员数量" prop="memberNum">-->
<!--          <el-input v-model.trim="dialogForm.memberNum" clearable placeholder="请输入会员数量"/>-->
<!--        </el-form-item>-->
        <el-form-item label="消费金额" prop="amount">
          <el-input v-model.trim="dialogForm.amount" clearable placeholder="请输入消费金额"/>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="dialogForm.status">
            <el-radio :value="0">正常</el-radio>
            <el-radio :value="1">停用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <div class="flexs">
            <el-button type="primary" :loading="dialogParams.loading" @click="submitDialogForm(dialogFormRef)">
              确认
            </el-button>
            <el-button @click="resetDialogForm(dialogFormRef)">重置</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>

    <go-back/>
  </div>
</template>

<script setup>
import {
  getCurrentInstance,
  ref,
  reactive,
  onMounted,
  watch,
  computed
} from "vue"
import listMixins from "@mixins/hook/list"
import {
  useRouter
} from "vue-router"
import {
  CirclePlus, Search
} from "@element-plus/icons-vue"
import GoBack from "@components/GoBack.vue"
const router = useRouter()
const {
  proxy
} = getCurrentInstance()

/**
 * minxin列表加载
 */
const {
  page,
  pageSizeNum,
  pageSize,
  loading,
  totalNums,
  searchParams,
  searchBtnLoading,
  apiPath,
  list,
  dialogFormRef,
  dialogShow,
  dialogForm,
  dialogParams,
  handleSearch,
  getData,
  handleAdd,
  handleEdit,
  resetDialogForm,
  handleAllSelected,
  submitDialogForm,
  closeDialog,
  handleAction,
  handleDelete
} = listMixins()

// dialogForm.memberNum = "";
dialogForm.gradeName	= "";
dialogForm.amount	= "";
dialogForm.status	= 0;

apiPath.value = '/member/grade';

onMounted(() => {
  getData()
})
const dialogFormRules = reactive({
  amount:[{
    required: true,
    message: "请输入消费金额",
    trigger: "blur"
  }],
  gradeName:[{
    required: true,
    message: "请输入等级名称",
    trigger: "blur"
  }],
})
</script>

<style lang="less">

</style>